#include "TelephoneBook.h"
#include "TelephoneInfo.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

enum data
{
    INSERT=1,
    DELETE,
    MODIFY,
    VIEW,
    DISPLAY,
    SAVE,
    EXIT

};
void 

//菜单展示
void display_menu()

{
    printf("\n   电话簿菜单  \n");
    printf("1. 添加新联系人\n");
    printf("2. 删除新联系人\n");
    printf("3. 修改联系人号码\n");
    printf("4. 根据姓名查找联系人\n");
    printf("5. 查看所有用户\n");
    printf("6.保存\n");
    printf("7. 退出\n");

}
void DateIn(Telebook *t)
{
    FILE *f=fopen("./telephone.txt","r");
    if(!f){
        printf("文件读取失败\n");
        return;
    }
    while(!feof(f))
    {
        insert_Telebook(t,2)
    }
    fclose(f);
}


int main()
{  
    int choice=0;
    Telebook *t = InitTelebook();
    DateIn(t);
    do{
        display_menu();
        printf("请输入你的选择！\n");
        scanf("%d",&choice);
        switch (choice)
        {
            case INSERT:
                insert_Telebook(t,1);
                insert_sort(t,BiggerName);
                break;
            case DELETE:
                void * p = delete_Telebook(t, IsEqual);
                if(p != NULL)
                     ClearTeleInfo(p);
                break;             
            case MODIFY:
                modify_Telebook(t,IsEqual);
                break;
            case VIEW:
                printf("请输入要查找人姓名\n");
                char a[]={0};
                scanf("%s",a);
                void *s=BinarySearch(t,a,Namecmp);
                PrintTelInfo(s);
                break;
            case DISPLAY:
                   
                    char flag;
                    printf("逆序排列请输入y/n\n");
                    scanf("%c",&flag);
                    if(flag=='y')
                    {
                       display_Telebook2(t, PrintTelInfo);
                    }
                break;
            case SAVE:
                {
                    Save_Telbook(t,save);
                    break;
                }
            case EXIT:
                Clear_Telebook(t,ClearTeleInfo);
                break;
           default:
                printf("无效选择！再选一次\n");
                break;
           
        }
    }while(choice!=7);
 
   return 0;
}